package com.aliengen.thingple.driverapp.ui.activities;

import android.content.Intent;
import android.view.View;

import com.aliengen.thingple.driverapp.R;
import com.aliengen.thingple.driverapp.data.exception.InvalidTagException;
import com.aliengen.thingple.driverapp.data.models.CylinderTag;
import com.aliengen.thingple.driverapp.data.models.Report;
import com.aliengen.thingple.driverapp.data.models.Tag;
import com.aliengen.thingple.driverapp.ui.fragments.DialogRFIDReadingFragment;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;

/**
 * This class is part of the Thingple mobile application for the CMC168 Handheld reader.
 *
 * Copyright AlienGen Limited 2016. All rights reserved.
 *
 * @author Timothé Mermet-Buffet <tim@aliengen.com>
 */
@EActivity(R.layout.activity_cylinder_read)
public class CylinderReadActivity extends AbstractBaseActivity  implements DialogRFIDReadingFragment.ReadingDialogListener {
    DialogRFIDReadingFragment dialog;

    @Extra("report")
    Report report;

    @AfterViews
    public void init() {
        dialog = new DialogRFIDReadingFragment();
        dialog.init(this);
    }

    public void onClickReadCylinder(View view){dialog.startReading(); }

    public Tag getTagFromBytes(byte[] tag) throws InvalidTagException
    {
        return new CylinderTag(tag);
    }

    public void onReadingNew(Tag tag) {
        Intent nextScreen = new Intent(getApplicationContext(), AnomalyDefineActivity_.class);
        nextScreen.putExtra("report", report);
        nextScreen.putExtra("cylinder_tag", tag);
        startActivity(nextScreen);
        this.finish();
    }
}
